import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { PageRequest, PageData } from '@/utils/common/types';
import { SheetOutputDto, SheetOutputDtoSimple } from './admin/sheet/model';
import { SheetNode } from './model/sheet';

/** 报表模块表格URL枚举 */
enum Api {
  /** 获取表格报表概要 */
  GetSheetsSimple = '/api/rpt/getSheetsSimple',
  /** 获取看板报表 */
  GetSheets = '/api/rpt/getSheets',
  /** 根据编号获取表格报表 */
  GetSheetById = '/api/rpt/getSheetById',
  /** 根据编号获取表格报表节点 */
  GetSheetNodeById = '/api/rpt/getSheetNodeById',
}

//#region 获取表格报表概要
/**
 * 获取表格报表概要
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function getRptSheetsSimple(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<SheetOutputDtoSimple>>(
    {
      url: Api.GetSheetsSimple,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 获取表格报表
/**
 * 获取表格报表
 * @param request 分页请求
 * @param mode 错误消息模型
 */
export function getRptSheets(request: PageRequest, mode: ErrorMessageMode = 'message') {
  return httpClient.post<PageData<SheetOutputDto>>(
    {
      url: Api.GetSheets,
      params: request,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion

//#region 根据编号获取表格报表
/**
 * 根据编号获取表格报表
 * @param sheetId 表格编号
 * @param mode 错误消息模型
 */
export function getSheetById(sheetId: string | bigint, mode: ErrorMessageMode = 'message') {
  return httpClient.get<SheetOutputDto>(
    {
      url: Api.GetSheetById,
      params: { sheetId: sheetId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 根据编号获取表格报表节点
/**
 * 根据编号获取表格报表节点
 * @param sheetId 表格编号
 * @param mode 错误消息模型
 */
export async function getSheetNodeById(
  sheetId: string | bigint,
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.get<SheetNode>(
    {
      url: Api.GetSheetNodeById,
      params: { sheetId: sheetId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
